package cn.sangedon.review.analysis.service.impl;

import cn.sangedon.review.analysis.service.RedisServer;
import com.alibaba.fastjson.JSONObject;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

@Service
public class RedisServerImpl implements RedisServer {
    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    public boolean save(String key, Object data) {
        redisTemplate.opsForValue().set(key, JSONObject.toJSONString(data));
        return true;
    }

    @Override
    public Object get(String key) {
        return redisTemplate.opsForValue().get(key);
    }

    @Override
    public boolean saveList(String key, List list) {
        redisTemplate.opsForList().rightPush(key, list);
        return false;
    }

    @Override
    public List list(String key) {
        return redisTemplate.opsForList().range(key, 0, -1);
    }

    @Override
    public boolean saveMap(String key, String hashKey, Object data) {
        redisTemplate.opsForHash().put(key, hashKey, data);
        return false;
    }

    @Override
    public Object get(String key, String hashKey) {
        return redisTemplate.opsForHash().get(key, hashKey);
    }
}
